package lesson03.a;

import lesson03.Course;
import lesson03.Teacher;

import java.util.Scanner;

/**
 * 学生类
 */
public class Student {
    // 属性还有一种称呼叫做成员变量
    /** 学生姓名 */
    public String name;
    /** 学生年龄 */
    public int age;
    /** 学生性别 */
    public String gender;

    public Student(){
        // 1. 构造方法没有返回值（void都没有）
        // 2. 构造方法的名字必须和类名一致
        // 构造方法的作用是构造对象并初始化对象的属性
        // 如果不写构造方法，一个类中默认就有一个无参的构造方法
        // 如果写了构造方法，无参的构造方法就会被覆盖掉
    }
    public Student(String name){
        // 通过this关键字调用其他构造方法，必须写在当前构造方法的第一句
        this(name,20,"男");
        System.out.println("带一个参数的构造方法");

    }
    public Student(String name,int age,String gender){
        this.name = name;
        this.age = age;
        this.gender = gender;
    }
    /**
     * 自我介绍的方法
     */
    public void intro(){
        System.out.println(this);
        System.out.println("你好，我是" + this.name + "，今年"+this.age+"岁");
    }

    /**
     * 听课的方法
     */
    public void listen(Teacher teacher, Course course){
        System.out.println(this.name + "听"
                + teacher.name + "上" + course.name);
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 产生学生类的对象
        Student student = new Student();
        Student student1 = new Student();
        Student student2 = new Student("王五",30,"男");
        Student student3 = new Student("赵六");
        System.out.println(student);
        System.out.println(student1);
        System.out.println(student2);

        student.name = "张三";
        student.age = 20;
        student.gender = "男";
        student1.name = "李四";
        student1.age = 25;
        student1.gender = "女";
        System.out.println(student.name);
        student.intro();
        student1.intro();
        student2.intro();
        student3.intro();

        Teacher teacher = new Teacher("白老师");
        Course course = new Course("Java基础");
        Teacher teacher1 = new Teacher("胡老师");
        Course course1 = new Course("数据库基础");

        student.listen(teacher,course);
        student.listen(teacher1,course);
        student1.listen(teacher1,course1);

    }
}
